package com.xzit.rental.controller;

import com.xzit.rental.entity.Dept;
import com.xzit.rental.service.IDeptService;
import com.xzit.rental.utils.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 何时说晚安
 * @since 2024-12-05
 */
@RestController
@RequestMapping("/rental/dept")
public class DeptController {

    @Resource
    private IDeptService deptService;

    @PostMapping("")
    public Result list(@RequestBody Dept dept) {
        return Result.success().setData(deptService.selectList(dept));
    }
    // 查询部门树
    @GetMapping("")
    public Result tree(){
        return Result.success().setData(deptService.selectTree());
    }
    @PostMapping("save")
    public Result save(@RequestBody Dept dept) {
        return deptService.save(dept)?Result.success():Result.fail();
    }
    @PutMapping("")
    public Result update(@RequestBody Dept dept) {
        return deptService.updateById(dept)?Result.success():Result.fail();
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        return deptService.removeById(id)?Result.success():Result.fail();
    }
    @GetMapping("/{id}")
    public Result hasChildren(@PathVariable Integer id) {
        return deptService.hasChildren(id)?Result.success().setMessage("有")
                :Result.success().setMessage("无");
    }

}
